function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  // For Old Microsoft Browsers 
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // For Microsoft IE 6.0+ 
     }
     catch (e2) {
       xmlHttp = false;   // No Browser accepts the XMLHTTP Object then false 
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers 
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created 
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object 
 
function handleContactListResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
     	document.getElementById("contactList").innerHTML = xmlhttp.responseText;
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
function handleDetailContactResponse() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	        document.getElementById("detailContact").innerHTML = xmlhttp.responseText;
	     }
	     else {
	        alert("Error during AJAX call. Please try again");
	     }
	   }
}
function loadContactsFromGroup(select)
  {
	document.getElementById("detailContact").innerHTML = ""; // Clear the detail contact div 
    if (select.selectedIndex != 0){
    	if (xmlhttp) {
    		xmlhttp.onreadystatechange = handleContactListResponse;
    		xmlhttp.open("GET", "ContactList?cgid="+select.options[select.selectedIndex].value);
    		xmlhttp.send("");
    	} else {
    		alert("Your browser doesn't support AJAX. Please update it to a more recent version.");
    	}
    }
  }
  
function detailContact(contactId)
{
	if (xmlhttp) {
        xmlhttp.onreadystatechange = handleDetailContactResponse;
        xmlhttp.open("GET", "DetailContact?cid="+contactId);
        xmlhttp.send("");
    } else {
        alert("Your browser doesn't support AJAX. Please update it to a more recent version.");
    }
}
